<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    var a = [1, 3, 6, 3, 23, 76, 1, 34, 222, 6, 456, 221];

    function insertSort(array) {
      const len = array.length;
      let current, prev;

      for (let i = 1; i < len; i++) {
        current = array[i];
        prev = i - 1;

        while (prev >= 0 && array[prev] > current) {
          array[prev + 1] = array[prev];
          prev--;
        }
        array[prev + 1] = current;
      }
      return array;
    }
    console.log(insertSort(a));
  </script>
</html>
